#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define all(s) (s).begin(),(s).end()
#define endl "\n"
#define eb emplace_back
#define ins insert
#define pq priority_queue

using ll=long long;
using ull=unsigned long long;

constexpr int inf=0x3f3f3f3f;
constexpr ll llinf=0x3f3f3f3f3f3f3f3fll;

signed main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int T; cin>>T;
    while(T--)
    {
        int n; cin>>n;
        vector<int> a(n);
        for(auto &x: a) cin>>x;
        // 1 for red
        // 0 for blue
        vector<bool> col(n);
        int ans=0;
        for(int i=0; i<(1<<n); i++)
        {
            int res=0;
            for(int j=0; j<n; j++)
            {
                if((i>>j)&1) col[j]=1;
                else col[j]=0;
            }
            for(int j=1; j<n; j++)
            {
                for(int k=j-1; k>=0; k--)
                    if(col[j]==col[k])
                    {
                        if(a[j]==a[k]) res+=a[j];
                        break;
                    }
            }
            ans=max(ans, res);
        }
        cout<<ans<<endl;
    }
    return 0;
}